package task;

import machinery.Machinery;

/**
 * 任务类
 */
public class Task {
    private String name;
    private Machinery assignedMachinery;
    private TaskStatus status;
    
    public Task(String name, Machinery assignedMachinery) {
        this.name = name;
        this.assignedMachinery = assignedMachinery;
        this.status = TaskStatus.CREATED;
    }
    
    public void execute() {
        System.out.println("执行任务: " + name);
        status = TaskStatus.IN_PROGRESS;
        assignedMachinery.executeTask(name);
    }
    
    public void complete() {
        System.out.println("完成任务: " + name);
        status = TaskStatus.COMPLETED;
    }
    
    public void fail(String reason) {
        System.out.println("任务失败: " + name + ", 原因: " + reason);
        status = TaskStatus.FAILED;
    }
    
    // Getter方法
    public String getName() {
        return name;
    }
    
    public Machinery getAssignedMachinery() {
        return assignedMachinery;
    }
    
    public TaskStatus getStatus() {
        return status;
    }
} 